<?php

$xtpl = new XTemplate("modules/home/news.htm");

$page = $_GET['page'];
//--

//--
$waypathlink = '&raquo;&nbsp;<a href="#" class="waypath_sub">News Management</a>';
$xtpl->assign("waypathlink",$waypathlink);
//--
//--
//--
$add_button = $GUI->button_ren("New","javascript: add('?mod=home&act=news_task');");
$xtpl->assign("add_button",$add_button);
//--
$delete_button = $GUI->button_ren("Delete","javascript: del('DELETE', document.frmAddnews);");
$xtpl->assign("delete_button",$delete_button);
//--
//--
//--
$limit = 20;
$pagegroup_size = 10;
if (!$page||$page==0){
	$page=1;
}
$offset = ($page-1)*$limit;
//////
/////////////////////////
$sql_c = "SELECT COUNT(*) AS total_msg FROM {$DP}news WHERE id_lang=".$_SESSION['ID_LANG_ADM'];
$rs_c = mysql_query($sql_c);
list($numrec)=mysql_fetch_row($rs_c);
//////////////////////////
$rs = $DB->ZenDataList('news','','id_lang='.$_SESSION['ID_LANG_ADM'],'news_date DESC',$offset.','.$limit);

$no=1;
while($row = mysql_fetch_array($rs)){
	$row[no]=$no++;	
	if($no%2!=0)
		$row['class'] = "row1";
	else 
		$row['class'] = "row2";
	//--
	$row[edit_link] = '?mod=home&act=news_task&id='.$row['news_id'].'';
	//--

	$row['title']=stripslashes($row['news_title']);
	$row['id'] = $row['news_id'];

	if($row['is_feature'] == '0'){
		$row['act_img'] = 'tick_new2';
		$row['feature_link'] = '?mod=home&act=news&page='.$_GET['page'].'&doit=add&thisID='.$row['news_id'];
		$row['link_title'] = 'Click here to add this News to the Feature List';
	}else{
		$row['act_img'] = 'tick_new1';
		$row['feature_link'] = '?mod=home&act=news&page='.$_GET['page'].'&doit=remove&thisID='.$row['news_id'];
		$row['link_title'] = 'Click here to remove this News from the Feature List';
	}
	
	//--
	$xtpl->assign("list",$row);
	$xtpl->parse("center.list");
}
//--
$pages = pagenavigator($page,$numrec,$limit,$pagegroup_size,"row0","?mod=home&act=news");
$xtpl->assign("page",$page);
$xtpl->assign("pages",$pages);
$xtpl->assign("numrec",$numrec);

//--
//--
//--
if($_POST['type'] == "DELETE"){
	$checked_delete = $_POST[checked_delete];
	for ($i=0;$i<count($checked_delete);$i++) {
		$delete_list.= $checked_delete[$i].",";
	}
	if($delete_list){
		$delete_list = substr($delete_list,0,strlen($delete_list)-1);
		$delete_split=split(",",$delete_list);
		for($i=0;$i<count($delete_split);$i++){
			//--
			$sql = "SELECT news_image FROM {$DP}news WHERE news_id='".$delete_split[$i]."'";
			$row = $DB->SQLrecordset($sql);
			if($row[image] != ''){
				$dir_ = "../upload/news/thumb".$row[image];
				if(is_file($dir_)) @unlink($dir_);
			}	
			//--	
			$sql = "DELETE FROM {$DP}news WHERE news_id='".$delete_split[$i]."'";
			mysql_query($sql);
		}
	}
	if($_GET['page'] != '')
		$GUI->redir('?mod=home&act=news&page='.$_GET['page']);
	else
		$GUI->redir('?mod=home&act=news');
}

//$xtpl->parse("center");
//$xtpl->assign("center_file",$xtpl->text("center"));
//--
/*$xtpl->assign("path_site",$base_url);
//--
if($_SESSION[ses_admin_id] != ''){
	$xtpl->parse("MAIN.mainbody");
}elseif($_SESSION[ses_admin_id] == ''){	
	$xtpl->parse("MAIN.login");
}
//--
$xtpl->parse("MAIN");
eval("?".">".$xtpl->text("MAIN"));
*/
//-- Old Feature Function
/*if($_GET['thisID'] != ''){
	if($_GET['doit'] == 'add'){
		$value = '1';
	}elseif($_GET['doit'] == 'remove'){
		$value = '0';
	}
	$sql = "UPDATE {$DP}news SET is_feature = '".$value."' WHERE id = '".$_GET['thisID']."'";
	mysql_query($sql);
	$GUI->redir('?mod=home&act=news&page='.$_GET['page']);
}*/
//--
?>